feat(imports): add mergeStrategy field to support deep merge#3103
Open
JordanGoasdoue wants to merge 2 commits into
Open
feat(imports): add mergeStrategy field to support deep merge#3103JordanGoasdoue wants to merge 2 commits into
JordanGoasdoue wants to merge 2 commits into
Conversation
✅ Deploy Preview for devspace-docs canceled.Built without sensitive environment variables
|
Signed-off-by: JordanGoasdoue <jordan.goasdoue@dailymotion.com>
058e688 to
8cba970
Compare
Collaborator
77c6c15 to
2bf5d7e
Compare
Author
|
Good point @zerbitx, you were right. I've reworked it. Deep merge is now opt-in via a imports:
- path: catalog.yaml
mergeStrategy: deepMergeI added tests for the mutually exclusive fields you flagged. When
Both cases also tested with Let me know what you think! |
Signed-off-by: JordanGoasdoue <jordan.goasdoue@dailymotion.com>
2bf5d7e to
d03c8b3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What issue type does this pull request address?
/kind feature
What does this pull request do? Which issues does it resolve?
Adds an opt-in
mergeStrategyfield on imports to support recursive deep merge of config sections.Problem:
When importing a config (e.g., from a git catalog), the current implementation only does a shallow merge at the first level. If both the imported config and the local config define the same section (like
dev.api), nested maps are completely replaced instead of being merged.Example:
Before: Local
dev.apireplaces catalog entirely, losesversion: v1,command, etc.After (with
mergeStrategy: deepMerge): Maps are deep merged, keeps bothapp: my-appandversion: v1Solution:
A new
mergeStrategyfield on each import entry, with two values:shallowMerge(default, current behavior): only top-level keys within each section are merged. Existing keys in the local config take precedence entirely.deepMerge(opt-in): maps are merged recursively. Arrays and scalars in the local config still take precedence.Merge rules when
deepMergeis enabled:This enables the common use case where organizations maintain a shared catalog in git, and projects only need to override specific values (like
labelSelector) while inheriting everything else (ports, sync config, commands, etc.).Please provide a short message that should be published in the DevSpace release notes
Imports now support a
mergeStrategyfield. SetmergeStrategy: deepMergeon an import to enable recursive map merging, allowing projects to inherit shared catalog configs while only overriding specific nested values. Default behavior (shallowMerge) is unchanged.What else do we need to know?
shallowMerge, which preserves the existing behavior exactly. No existing config is affected.deepMergecombines fields that shouldn't coexist, the existing validations invalidate.gocatch it properly. This is tested explicitly:deployments:helm+kubectlon the same deployment triggers"deployments[x].kubectl and deployments[x].helm cannot be used together"dev:imageSelector+labelSelectoron the same dev pod triggers"dev.x: image selector and label selector cannot be used together"shallowMergeto prove no regression (the conflicting field from the catalog is simply ignored)TestImportsDeepMerge(deep merge scenarios, default shallow, explicit shallow, mutually exclusive field validation in bothdeploymentsanddevsections)deepMerge(edge cases: empty maps, 3-level nesting, type mismatches, nil values)shallowMergedevspace-schema.json,config-openapi.json) regenerated, IDE autocomplete works out of the box